<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="8">
        <el-card shadow="hover" class="mgb20" style="height: 252px">
          <div class="user-info">
            <img v-if="img" :src="`${IMG_URL}${avator}`" class="user-avator" alt />
            <!-- <img v-else src="`${IMG_URL}${scope.row.avator}`" class="user-avator" alt /> -->
            <img v-else src="../../assets/img/img.jpg" class="user-avator" alt />
            <div class="user-info-cont">
              <div class="user-info-name">{{ name }}</div>
              <div>管理员</div>
              <!-- <div>{{ role }}</div> -->
            </div>
          </div>
          <div class="user-info-list">
            上次登录时间：
            <span>{{ time }}</span>
          </div>
          <div class="user-info-list">
            用户所在地点：
            <span>{{ address }}</span>
          </div>
        </el-card>
        <el-card shadow="hover" style="height: 252px">
          <template #header>
            <div class="clearfix">
              <span>景点热度</span>
            </div>
          </template>
          颐和园
          <el-progress :percentage="71.3" color="#42b983"></el-progress>故宫
          <el-progress :percentage="24.1" color="#f1e05a"></el-progress>天坛公园
          <el-progress :percentage="13.7"></el-progress>圆明园
          <el-progress :percentage="5.9" color="#f56c6c"></el-progress>
        </el-card>
      </el-col>
      <el-col :span="16">
        <el-row :gutter="20" class="mgb20">
          <el-col :span="8">
            <el-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-1">
                <el-icon class="grid-con-icon">
                  <UserFilled />
                </el-icon>
                <div class="grid-cont-right">
                  <div class="grid-num">1234</div>
                  <div>用户访问量</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="8">
            <el-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-2">
                <el-icon class="grid-con-icon">
                  <BellFilled />
                </el-icon>
                <div class="grid-cont-right">
                  <div class="grid-num">321</div>
                  <div>系统消息</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="8">
            <el-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-3">
                <el-icon class="grid-con-icon">
                  <!-- <GoodsFilled /> -->
                  <Histogram />
                </el-icon>
                <div class="grid-cont-right">
                  <div class="grid-num">5000</div>
                  <div>数量</div>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <el-card class="box-card">
          <template #header>
            <div class="clearfix">
              <span>最新评论</span>
              <el-button style="float: right; padding: 3px 0" link type="primary">更多</el-button>
            </div>
          </template>
          <div :show-header="false" v-for="(i, index) in commentList" :key="index" class="text item text-overflow"
            style="height: 61px;line-height: 61px;margin-left:20px;border-bottom:1px solid grey">
            {{ commentList[index] }}
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
// @ is an alias to /src
import { reactive, ref } from "vue";
import { IMG_URL } from "@/utils/imgStatic";
import request from "../../utils/request";

const userInfo = localStorage.getItem("userInfo");
// if (userInfo == "{}" || !userInfo) {
//   localStorage.setItem(
//     "userInfo",
//     JSON.stringify({
//       user: {
//         username: "cry",
//         type: "0",
//         updatedAt: "2023-09-19 19:28:32",
//         address: "cqie",
//       },
//     })
//   );
// }
const user = JSON.parse(localStorage.getItem("userInfo")).user;

const img = ref(false);
if (user.avator) {
  img.value = true;
}

const name = user.username;
const avator = user.avator;
const time = user.updatedAt;
const address = user.address;
const imgUrl = `${IMG_URL}${user.avator}`;

const query = reactive({
  u_id: "",
  content: "",
  currentPage: 1,
  pageSize: 5,
  type: "",
});
const tableData = ref([]);
const commentList = ref([]);
const totalCount = ref(0);
const getData = () => {
  request
    .request({
      url: "/comment/getAllCommentsByPage",
      params: {
        type: query.type,
        u_id: query.u_id,
        c_id: query.c_id,
        content: query.content,
        currentPage: query.currentPage,
        pageSize: query.pageSize,
      },
      method: "get",
    })
    .then((res) => {
      //获取当前页的数据
      tableData.value = res.data.data.rows;
      //获取总记录数
      totalCount.value = res.data.data.count;

      for (let i = 0; i < 5; i++) {
        commentList.value.push(tableData.value[i].content);
      }
      // console.log(tableData);
      // console.log(totalCount);
    })
    .catch((e) => {
      console.log(e);
    });
};

getData();

</script>

<style scoped>
.el-row {
  margin-bottom: 20px;
}

.grid-content {
  display: flex;
  align-items: center;
  height: 100px;
}

.grid-cont-right {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: #999;
}

.grid-num {
  font-size: 30px;
  font-weight: bold;
}

.grid-con-icon {
  font-size: 50px;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  color: #fff;
}

.grid-con-1 .grid-con-icon {
  background: #2d8cf0;
}

.grid-con-1 .grid-num {
  color: #2d8cf0;
}

.grid-con-2 .grid-con-icon {
  background: #64d572;
}

.grid-con-2 .grid-num {
  color: #2d8cf0;
}

.grid-con-3 .grid-con-icon {
  background: #f25e43;
}

.grid-con-3 .grid-num {
  color: #f25e43;
}

.user-info {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 2px solid #ccc;
  margin-bottom: 20px;
}

.user-avator {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

.user-info-cont {
  padding-left: 50px;
  flex: 1;
  font-size: 14px;
  color: #999;
}

.user-info-cont div:first-child {
  font-size: 30px;
  color: #222;
}

.user-info-list {
  font-size: 14px;
  color: #999;
  line-height: 25px;
}

.user-info-list span {
  margin-left: 70px;
}

.mgb20 {
  margin-bottom: 20px;
}

.todo-item {
  font-size: 14px;
}

.todo-item-del {
  text-decoration: line-through;
  color: #999;
}
.text-overflow {
  white-space: nowrap; /* 不换行 */
  overflow: hidden; /* 隐藏超出的内容 */
  text-overflow: ellipsis; /* 用省略号表示被隐藏的部分 */
  max-width: 900px; /* 设置最大宽度以限制文本的显示长度 */
}
</style>
